# Makefile内容通常由以下部分组成
# <目标>: <前置依赖>
#   <需要执行的命令>

# 放在第一个的是默认目标

# main:main.c hello.c hello.h
# 	gcc main.c hello.c -o main
# 	./main
# 	rm ./main 




log := thirdparty/log/src/log.h thirdparty/log/src/log.c
log_test : test/log_test.c $(log)
	-gcc $(CFLAGS) $^ -o $@ -I thirdparty
	./$@
	-rm $@

json:=thirdparty/cJSON/cJSON.h thirdparty/cJSON/cJSON.c

cJSON_test: test/cJSON_test.c $(json) $(log)
	-$(CC) $^ -o $@ -I thirdparty
	-./$@
	-rm $@


app_common := app/app_common.h app/app_common.c
app_common_test: test/app_common_test.c $(app_common) $(log)
	-$(CC) $^ -o $@ -I thirdparty -I app
	-./$@
	-rm $@

app_message := app/app_message.h app/app_message.c
app_message_test: test/app_message_test.c $(app_message) $(app_common) $(log) $(json)
	-$(CC) $^ -o $@ -I thirdparty -I app
	-./$@
	-rm $@


mqtt_test: test/mqtt_test.c
	-$(CC) $^ -o $@ -lpaho-mqtt3c
	-./$@
	-rm $@

#=================线程测试=======================================
create: test/01_create.c
	-$(CC) $^ -o $@
	-./$@
	-rm $@

sum_sqr:test/02_sum_sqr.c
	gcc -o $@ $^
	-./$@
	-rm $@ 

sum_sqr_t_join:test/02_sum_sqr_thread.c
	-gcc -o $@ $^
	-./$@
	-rm $@

cancel: test/03_cancel.c
	-$(CC) $^ -o $@
	-./$@
	-rm $@

race_condition: test/04_race_condition.c
	-$(CC) $^ -o $@
	-./$@
	-rm $@

mqueue_test: test/05_mqueue_test.c
	-$(CC) $^ -o $@
	-./$@
	-rm $@


app_pool:=app/app_pool.h app/app_pool.c
test/app_pool_test: test/app_pool_test.c $(log) $(app_pool)
	-$(CC) -o $@ $^ -I thirdparty -I app
	-./$@
	-rm ./$@

app_buffer := app/app_buffer.h app/app_buffer.c
app_buffer_test: test/app_buffer_test.c $(app_buffer) $(log)
	-$(CC) $^ -o $@ -I thirdparty -I app
	./$@
	-rm $@


system_call: test/io/01_system_call.c
	-$(CC) $^ -o $@
	-./$@
	-rm $@

std_io: test/io/02_std_io.c
	-$(CC) $^ -o $@
	-./$@
	-rm $@

std_io_redirect: test/io/03_std_io_redirect.c
	-$(CC) $^ -o $@
	-./$@
	-rm $@